package com.yiren.backstage.judge.thread;
import android.content.Context;

import com.yiren.backstage.currency.constant.AutoJudgeConstant;
import com.yiren.backstage.currency.entity.ProjectEntity;
import com.yiren.backstage.currency.enums.TaskStateEnum;
import com.yiren.backstage.currency.utils.MessageUtil;
import com.yiren.backstage.judge.api.IExamStateCallBack;
import com.yiren.backstage.judge.handler.AutoJudgeHandler;
import com.yiren.backstage.judge.services.sczb.ISczbJudgeThreadService;
import com.yiren.backstage.judge.services.sczb.impl.SczbJudgeThreadServiceImpl;

import java.util.Timer;

/**
 * Time:2022/4/7 16:29
 * Author:xiaozan
 * Description:上车准备项目评判线程
 */
public class SczbJudgeThread implements Runnable{

    private AutoJudgeHandler autoJudgeHandler;

    private ProjectEntity projectEntity;

    private ISczbJudgeThreadService iSczbJudgeThreadService;

    /**当前上车准备执行步骤*/
    private int step = 1;

    public SczbJudgeThread(Context context, AutoJudgeHandler autoJudgeHandler,ProjectEntity projectEntity){
        this.autoJudgeHandler = autoJudgeHandler;
        this.projectEntity = projectEntity;
        iSczbJudgeThreadService = new SczbJudgeThreadServiceImpl(context,autoJudgeHandler,projectEntity);

    }

    @Override
    public void run() {
        try {
            while(autoJudgeHandler.getTaskStateEnum() != TaskStateEnum.FORCT_CLOSE){
                switch (step){
                    case 1://提示关闭发动机
                        boolean closeEngine = iSczbJudgeThreadService.tipsPlayCloseEngine();
                        if(!closeEngine) step = 2;
                        break;
                    case 2://播报身份验证语音
                        boolean playAuthenticationVoice = iSczbJudgeThreadService.playAuthenticationVoice();
                        if(!playAuthenticationVoice) step = 3;
                        break;
                    case 3://检测绕车
                        iSczbJudgeThreadService.operationPlayVoice();
                        if (iSczbJudgeThreadService.executeJudge()) return;
                        break;
                }
                Thread.sleep(10);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
